﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;


using ZhimeiSoft.Framework.Client.Base;
using ZhimeiSoft.Framework.Client.Utils;
using ZhimeiSoft.CharmManager.Client.Manager;
using ZhimeiSoft.CharmManager.DOL;
namespace ZhimeiSoft.CharmManager.Client.Forms
{
    public partial class EmployeeInfoBrows : BaseUserControl
    {
        //店信息
        private SortedList<int, string> sortSalonInfo = new SortedList<int,string>(); 

        public EmployeeInfoBrows()
        {
            InitializeComponent();
            cbxEmployeeState.SelectedItem = cbxF0E;
            InitData();

            ButtonItemIconHelper.InitRibbonBar(this.ribbonBar1);
        }

        private void buttonX4_Click(object sender, EventArgs e)
        {

        }

        private void btnAddEmployee_Click(object sender, EventArgs e)
        {
            frmEmployeeAdd frmadd = new frmEmployeeAdd();
            frmadd.employeeInfo = null;
            if (frmadd.ShowDialog() == DialogResult.OK)
            {
                //刷新数据集
                InitData();
            }
        }

        private void btnEditEmployee_Click(object sender, EventArgs e)
        {
            if (cardviewEmployee.FocusedRowHandle < 0) {
                MsgBox.MsgInfo("请选择正确的员工记录。");
                return;
            }
            DataRow drEmployee = cardviewEmployee.GetDataRow(cardviewEmployee.FocusedRowHandle);
            DBEntityEmployee employeeInfo = new DBEntityEmployee(drEmployee);
            frmEmployeeAdd frmadd = new frmEmployeeAdd();
            frmadd.employeeInfo = employeeInfo;
            if (frmadd.ShowDialog() == DialogResult.OK)
            {
                //刷新数据集
                InitData();
            }    
        }

        private void InitData()
        {
            if (cbxEmployeeState.SelectedItem == null)
                cbxEmployeeState.SelectedItem = cbxF0E;

            string sChiState = cbxEmployeeState.SelectedItem.ToString();
            string sEnumState = DBEntityEmployee.ENUM_ESTATE.ChineseStrToEnumStr(sChiState);
            DataSet dsEmployee = new DataSet();
            string error = string.Empty;
            if (BussinessProxyManager.Instance == null)
            {
                return;
            }

            bool bFlag = BussinessProxyManager.Instance.QeuryEmployeeFilter(string.Empty, out dsEmployee, out error);
            if (bFlag == false)
            {
                MsgBox.MsgInfo("获取员工数据出现错误\r\n" + error);
                return;
            }

            string sRowFilter = string.Format("{0}='{1}'", DBEntityEmployee.FieldName.ESTATE, sEnumState);
            DataView dv = dsEmployee.Tables[0].DefaultView;
            dv.RowFilter = sRowFilter;
            gdEmployeeInfo.DataSource = dv;
        }

        private void cardviewEmployee_CustomDrawCardFieldValue(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            Rectangle r = e.Bounds;
            string sText = string.Empty;
            if (e.Column.FieldName == DBEntityEmployee.FieldName.ESTATE)
            {
                sText = DBEntityEmployee.ENUM_ESTATE.EnumStrToChineseStr(e.CellValue.ToString());
                e.Style.DrawString(e.Graphics, sText, r);
                e.Handled = true;
            }
            else if (e.Column.FieldName == DBEntityEmployee.FieldName.ISRESERVERATION)
            {
                sText = "否";
                if (e.CellValue.ToString() == "1")
                {
                    sText = "是";
                }
                e.Style.DrawString(e.Graphics, sText, r);
                e.Handled = true;
            }
        }

        private void cardviewEmployee_DoubleClick(object sender, EventArgs e)
        {
            btnEditEmployee_Click(null, null);
        }

        private void cbxEmployeeState_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (gdEmployeeInfo.DataSource == null)
                return;

            DataView dv = (DataView)gdEmployeeInfo.DataSource;
            string sChiState = cbxEmployeeState.SelectedItem.ToString();
            string sEnumState = DBEntityEmployee.ENUM_ESTATE.ChineseStrToEnumStr(sChiState);
            string sRowFilter = string.Format("{0}='{1}'", DBEntityEmployee.FieldName.ESTATE, sEnumState);
            dv.RowFilter = sRowFilter;
        }

        
    }
}
